<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<title>商品类别信息管理</title>
	</head>
	<body>
		<center>
			<h3>商品类别信息管理</h3>
			<table width="700" border="1">
				<tr>
					<th>类别ID</th>
					<th>类别名称</th>
					<th>父类别ID</th>
					<th>PATH路径</th>
					<th>操作</th>
				</tr>
				<?php 
					//导入配置文件
					require("../../public/config.php");
					$link = @mysqli_connect(HOST,USER,PASS,DBNAME);//连接数据库
					if(!$link){
						die("数据库连接失败！原因".mysqli_connect_error());
					}
					
					mysqli_set_charset($link,"utf8");	//设置编码格式
					$sql = "select * from type order by concat(path,id)";	//设置sql语句
					$result = mysqli_query($link,$sql);	//发送sql语句并接收结果集
					while($row = mysqli_fetch_assoc($result)){	//解析结果集
						$m = substr_count($row['path'],",")-1;	//判断字段的','有多少个
						$nbsp = str_repeat("&nbsp;",$m*3);		//在值前面输出空格
						echo "<tr>";							//遍历输出
						echo "<td>{$row['id']}</td>";
						echo "<td>{$nbsp}|--{$row['name']}</td>";
						echo "<td>{$row['pid']}</td>";
						echo "<td>{$row['path']}</td>";
						echo "<td><a href='add.php?pid={$row['id']}&path={$row['path']}&name={$row['name']}'>添加子分类</a>
							  <a href='edit.php?a=update&id={$row['id']}&pid={$row['pid']}&path={$row['path']}'>修改</a>
							  <a href='action.php?a=del&id={$row['id']}'>删除</a></td>";
						echo "</tr>";
					}
					mysqli_free_result($result);				//关闭结果集
					mysqli_close($link);						//关闭数据库连接
				 ?>
			</table>
		</center>
		</table>
	</body>
</html>